package com.web58.velocity.dao;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;

import com.web58.velocity.bean.User;


public class UserDao {
	
	private  HashMap <Integer,User> data=new HashMap<Integer, User>();

	public User findByName(String name){
		Set<Entry<Integer, User>> enties=data.entrySet();
		Iterator<Entry<Integer, User>> iterator=enties.iterator();
		User result=null;
		while(iterator.hasNext()){
			Entry<Integer, User> entry=iterator.next();
			User user=entry.getValue();
			if(user.getUserName().equals(name)){
				result=user;
				break;
			}
		}
		
		return result;
	}


	public void insert(User user){
		data.put(user.getId(), user);
	}
	
	public void delete(User user){
		data.remove(user.getId());
	}
}
